﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using V5_Model;
using V5_Common;
using V5_BLL;

namespace V5_EShop._Template.Default
{
    public partial class product_ask : BasicPage
    {
        public ModelProduct product = new ModelProduct();
        int productid = 0;
        protected override void OnInit(EventArgs e)
        {
            this.btnSave.Click += new EventHandler(btnSave_Click);
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.check_member_login())
            {
                Response.Redirect("/login.aspx?returnurl=" + HTTPS.GetCurrentUrl());
            }
            if (!this.IsPostBack)
            {
                productid = Input.SetInt(Request["productid"]);
                if (productid > 0)
                {
                    this.hfID.Value = productid.ToString();
                    product = new BLLProduct().GetModel(productid);
                }
            }
        }

        void btnSave_Click(object sender, EventArgs e)
        {
            int id = Input.SetInt(this.hfID.Value);
            if (Input.SqlFilter(Input.SetString(txtAskName.Text)) || Input.SqlFilter(Input.SetString(txtAskContent.Text)))
            {
                Response.Redirect(HTTPS.ComeUrl);
                return;
            }
            string AskName = Input.SetString(txtAskName.Text);
            string AskContent = Input.SetString(txtAskContent.Text);
            if (id > 0)
            {
                BLLProductAsk bll = new BLLProductAsk();
                ModelProductAsk model = new ModelProductAsk();
                model.AskTitle = AskName;
                model.AskContent = AskContent;
                model.MemberID = user.ID;
                model.ProductID = id;
                model.Passed = 0;
                model.AddDateTime = DateTime.Now;
                model.GetIP = HTTPS.GetIP;
                bll.Add(model);
                Pr.RegClientAlertAndRedirect(this, "您的提问已经提交给管理员审核!请耐心等待", HTTPS.ComeUrl);
            }
        }
    }
}
